home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 December
/
Chip_2000-12_cd1.bin
/
zkuste
/
MacOS
/
Files
/
Windox.sit
/
Windox 1.0
/
Source
/
Windox.c
next >
Wrap
C/C++ Source or Header
|
1993-06-29
|
6KB
|
213 lines
// SuperGrow.c ⌐ 1992 Hugues Marty
//*****************************************************************************
#define findWindowTrap 0xa92c
#define growWindowTrap 0xA92B
#define baseIcon 128
//*****************************************************************************
pascal long BWGrowWindow(WindowPtr theWindow, Point startPt, Rect *sizeRect);
pascal void ShowInit(short, short);
long oldGrowWindow;
long gneResult;
Pattern grayPat = {0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55};
//*****************************************************************************
main() // main must be at top of resource
{
asm {
// setup code here (INIT time)
clr.b -(sp) // Test mouse down
Button
tst.b (sp)+
bne.s @dontLoad
sub #sizeof(KeyMap),sp // Test shift key
pea (sp)
GetKeys
btst #0,7(sp)
add #sizeof(KeyMap),sp
bne.s @dontLoad
// keep code in system heap
lea main,a0 // float ourselves in system heap
move.l a0,a4
RecoverHandle // call recoverhandle
move.l a0,-(sp) // to get handle
DetachResource // and detachresouce to release ourselves
move.l #growWindowTrap,d0
GetToolTrapAddress
move.l a0,oldGrowWindow
lea BWGrowWindow,a0
move.l #growWindowTrap,d0
SetToolTrapAddress
move.w #baseIcon,-(sp)
@away move.w #-1,-(sp)
bsr ShowInit
rts
@dontLoad move.w #baseIcon+1,-(sp)
bra.s @away
}
}
typedef struct {
long top, left, bottom, right;
} LongRect;
pascal long BWGrowWindow(register WindowPtr theWindow, Point startPt, Rect *sizeRect)
{
long result;
Rect oldRect, newRect, curRect;
GrafPtr oldPort;
GrafPtr wMgrPort;
PenState penState;
Rect bmRect;
Point newPt;
char theKeys[16] /*instead of KeyMap*/;
LongRect sizeLeft, sizeRight; // Bounds
Boolean cmdDown, optDown, shiftDown;
asm {
movem.l d1-d7/a1-a5,-(sp) // save registers
lea main,a4 // setup a4 for globals
}
// Now, do our stuff...
// Prepare port
GetPort(&oldPort);
GetWMgrPort(&wMgrPort);
SetPort(wMgrPort);
SetClip(GetGrayRgn());
ClipAbove(theWindow);
GetPenState(&penState);
PenNormal();
PenMode(notPatXor);
PenPat(grayPat);
newRect = theWindow->portRect;
bmRect = theWindow->portBits.rowBytes < 0 ?
( **( ((CGrafPtr) theWindow)->portPixMap) ).bounds :
theWindow->portBits.bounds;
OffsetRect(&newRect, -bmRect.left, -bmRect.top);
oldRect = curRect = newRect;
// newRect est maintenant le rectangle de la fenÉtre en coord. globales.
startPt.v = oldRect.bottom - startPt.v;
startPt.h = oldRect.right - startPt.h;
sizeRight.top = (long) topLeft(oldRect).v + sizeRect->top - startPt.v;
sizeRight.left = (long) topLeft(oldRect).h + sizeRect->left - startPt.h - 1;
sizeRight.bottom = (long) topLeft(oldRect).v + sizeRect->bottom - startPt.v;
sizeRight.right = (long) topLeft(oldRect).h + sizeRect->right - startPt.h - 1;
sizeLeft.top = (long) botRight(oldRect).v - sizeRect->bottom;
sizeLeft.left = (long) botRight(oldRect).h - sizeRect->right + 1;
sizeLeft.bottom = (long) botRight(oldRect).v - sizeRect->top;
sizeLeft.right = (long) botRight(oldRect).h - sizeRect->left + 1;
asm { bsr @paintWStruct }
while (WaitMouseUp()) {
/* loop here */
GetMouse(&newPt);
GetKeys(theKeys);
cmdDown = theKeys[6] & 0x80;
shiftDown = theKeys[7] & 0x01;
optDown = theKeys[7] & 0x04;
curRect = oldRect;
if (newPt.h < topLeft(oldRect).h) {
if ((! cmdDown) && newPt.h < sizeLeft.left) newPt.h = sizeLeft.left;
curRect.left = newPt.h;
} else if (optDown && newPt.h < botRight(oldRect).h) {
if (newPt.h > sizeLeft.right) newPt.h = sizeLeft.right;
curRect.left = newPt.h;
} else {
if (newPt.h < sizeRight.left) newPt.h = sizeRight.left;
if ((! cmdDown) && newPt.h > sizeRight.right) newPt.h = sizeRight.right;
curRect.right = newPt.h + startPt.h;
}
if (newPt.v < topLeft(oldRect).v) {
if ((! cmdDown) && newPt.v < sizeLeft.top) newPt.v = sizeLeft.top;
curRect.top = newPt.v;
} else if (shiftDown && newPt.v < botRight(oldRect).v) {
if (newPt.v > sizeLeft.bottom) newPt.v = sizeLeft.bottom;
curRect.top = newPt.v;
} else {
if (newPt.v < sizeRight.top) newPt.v = sizeRight.top;
if ((! cmdDown) && newPt.v > sizeRight.bottom) newPt.v = sizeRight.bottom;
curRect.bottom = newPt.v + startPt.v;
}
if (! EqualRect(&newRect, &curRect)) {
asm { bsr @paintWStruct }
newRect = curRect;
asm { bsr @paintWStruct }
}
}
asm { bsr @paintWStruct }
// If window must move, do it
if (*(long*)&newRect != *(long*)&oldRect)
MoveWindow(theWindow, newRect.left, newRect.top, false);
result = EqualRect(&oldRect, &newRect) ?
0 :
(long) (newRect.bottom - newRect.top) << 16 |
((long) (newRect.right - newRect.left) & 0xffff);
SetPenState(&penState);
SetPort(oldPort);
asm {
movem.l (sp)+,d1-d7/a1-a5 // Restore everything
}
return result;
/******************/
@paintWStruct:
asm {
sub #sizeof(long)+sizeof(short),sp
// room for result & variant
move.l theWindow,-(sp) //
GetWVariant // GetWVariant(theWindow)
move.l theWindow,-(sp) // theWindow
move.w #wGrow,-(sp) // message = wGrow
pea newRect // param = &newRect
// windowProc (Handle)
movea.l OFFSET(WindowRecord,windowDefProc)(theWindow),a0
tst.l (a0)
bne.s @1
move.l a0,d0
StripAddress
move.l d0,-(sp)
LoadResource
@1 HLock
movea.l (a0),a0 // a0 = &wdef
jsr (a0)
// wdef(varCode, theWindow, wGrow, &newRect) : longint
movea.l OFFSET(WindowRecord,windowDefProc)(theWindow),a0
// unlock wdef handle !
HUnlock
move.l (sp)+,d0 // pop wdef result code
rts
}
}